define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'statistics/diagnosis/index',
                    //add_url: 'users/user/add',
                    //edit_url: 'users/user/edit',
                    //del_url: 'users/user/del',
                    //for_url: 'users/user/for',
                    multi_url: 'statistics/diagnosis/multi',
                    table: 'diagnosis',
                }
            });

            var table = $("#table");

            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                //console.log(data);
                //这里我们手动设置底部的值
                $("#cishu").text(data.extend.cishu);
                $("#money").text(data.extend.money);
                $("#cost").text(data.extend.cost);
                $("#sum").text(data.extend.sum);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                commonSearch: true,
                searchFormVisible: true,
                visible: false,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('序号'), formatter: function(value, row, index){
                                return ++index;
                            }, operate: false},
                        {field: 'create_time', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'code', title: __('服务单号'), operate: 'LIKE'},
                        {field: 'info.name', title: __('就诊人'), operate: 'LIKE'},
                        {field: 'age', title: __('年龄'), operate: false},
                        {field: 'info.sex', title: __("性别"), searchList: {"男":__('男'),"女":__('女')}, formatter: Table.api.formatter.status},
                        {field: 'info.address', title: __('居住地址'), operate: 'LIKE'},
                        {field: 'disease_name', title: __('看诊项目'), operate: 'LIKE'},
                        {field: 'medic.name', title: __('专家'), operate: 'LIKE'},
                        {field: 'salesman_name', title: __('健康顾问'), operate: 'LIKE'},
                        {field: 'money', title: __('诊疗应收金额'), operate: false},
                        {field: 'drugs_cost', title: __('原材料成本金额'), operate: false},
                        {field: 'exploit', title: __('开发维护费用'), operate: false},
                        {field: 'cure', title: __('治疗费用'), operate: false},
                        {field: 'commission', title: __('代理费'), operate: false},
                        {field: 'discounted', title: __('折扣费'), operate: false},
                        {field: 'royalties', title: __('提成费'), operate: false},
                        {field: 'assess', title: __('疗效评估'), operate: false},
                        //{field: 'image', title: __('头像'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        //{field: 'draw', title: __('抽奖次数'), operate: false, sortable: true},
                        //{field: 'userss.name', title: __('上级姓名'), operate: 'LIKE', sortable: true},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        //{field: 'status', title: __("状态"), searchList: {"0":__('待缴费'),"1":__('部分缴费'),"2":__('缴费完成'),"3":__('已关闭')}, formatter: Table.api.formatter.status},
                        // {field: 'operate', title: __('Operate'), table: table,
                        //     events: Table.api.events.operate,
                        //     buttons: [{
                        //         name: 'detail',
                        //         text: __('Detail'),
                        //         icon: 'fa fa-list',
                        //         classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                        //         url: 'financing/registration/detail'
                        //     }],
                        //     formatter: Table.api.formatter.operate
                        // },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            //添加以下部分
            // $(document).on("click",".btn-for",function(){
            //
            //     var ids = Table.api.selectedids(table);
            //     //var url = options.extend.for_url;
            //     var url = 'users/user/for';
            //     console.log(url);
            //
            //     if (url.indexOf("{ids}") !== -1){
            //         url = Table.api.replaceurl(url,{ids:ids.length > 0 ? ids.join(","):0});
            //     }
            //     Fast.api.open(url,'123',$(this).data() || {})
            // });

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        for: function () {
            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }

    };
    return Controller;
});